package control

import (
	"dicomtodb/models"
	"sync"
	"time"
)

var lock sync.Mutex

func contrastData() {
	defer models.Wait.Done()
	defer models.Log.DEBUG("contrastData is quit~!!")
	var newfile models.FileInfo
loop:
	for {
		//查询不到 终结循环
		lock.Lock()
		rows, awaitddata := newfile.GetRows(200)
		lock.Unlock()
		if rows <= 0 {
			break loop
		}
		//awaitddata := models.CountrastFile()
		countData := rows
		models.Log.INFO("本次待处理%d 个文件", countData)
		if countData <= 0 {
			models.Log.INFO("数据库中信息对比完成，无处理文件～！")
			return
		}
		for _, d := range awaitddata {
			select {
			case FileInfoChan <- d:
				lock.Lock()
				d.UpdataAsDicomStatus(true)
				lock.Unlock()
				models.Log.DEBUG("%v写入管道FileinofChan完成", d)
			default:
				models.Log.INFO("FileinofChan当前长度:%d,容量: %d", len(FileInfoChan), cap(FileInfoChan))
				time.Sleep(10 * time.Second)

			}

		}
	}
	close(FileInfoChan)
	models.Log.INFO("待处理文件发送完成")
}
